﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cms.Domain
{
    public class CustomAdminPage
    {
        private SourceCode _code;
        private SourceCode _xmlTranslations;
        private IList<AdministratorGroup> _allowedAdministratorGroups;
        private IList<AdministratorGroup> _deniedAdministratorGroups;

        public virtual int Id { get; set; }

        public virtual string Name { get; set; }

        public virtual string Filename { get; set; }

        public virtual Site Site { get; set; }

        public virtual bool ShowInMenu { get; set; }

        public CustomAdminPage()
        {
            _allowedAdministratorGroups = new List<AdministratorGroup>();
            _deniedAdministratorGroups = new List<AdministratorGroup>();
        }

        public virtual SourceCode Code
        {
            get { return _code; }
            set { _code = value; }
        }

        public virtual SourceCode XmlTranslations
        {
            get { return _xmlTranslations; }
            set { _xmlTranslations = value; }
        }

        public virtual IList<AdministratorGroup> AllowedAdministratorGroups
        {
            get { return _allowedAdministratorGroups; }
            set { _allowedAdministratorGroups = value; }
        }

        public virtual IList<AdministratorGroup> DeniedAdministratorGroups
        {
            get { return _deniedAdministratorGroups; }
            set { _deniedAdministratorGroups = value; }
        }

        public virtual string GetCode()
        {
            return _code != null ? _code.CurrentVersion.Code : string.Empty;
        }

        public virtual void SetCode(string code, Administrator editedBy)
        {
            if (_code == null)
            {
                _code = new SourceCode();
                _code.Site = Site;
            }
            _code.AddVersion(code, editedBy);
        }

        public virtual string GetXmlTranslations()
        {
            return _xmlTranslations != null ? _xmlTranslations.CurrentVersion.Code : string.Empty;
        }

        public virtual void SetXmlTranslations(string xml, Administrator editedBy)
        {
            if (_xmlTranslations == null)
            {
                _xmlTranslations = new SourceCode();
                _xmlTranslations.Site = Site;
            }
            _xmlTranslations.AddVersion(xml, editedBy);
        }
    }
}
